#include "Core/Log/LogManager.h"
#include "Core/Time/TimeMeasure.h"
#include "Core/Memory/MemoryPoolManager.h"
#include "Core/Profile/CodeProfile.h"
#include "MemoryTest.h"

const char * MemoryTest::GetName() const
{
	return "[CORE] Memory Test";
}

Core::error MemoryTest::Create()
{
	if(Failed(UnitTest::Create()))
			return Core::errFailed;

	return Core::errOK;
}

Core::error MemoryTest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return Core::errFailed;

	return Core::errOK;
}

Core::error MemoryTest::Execute()
{
	PROFILE(GetName());

	A1 * a1 =new A1;
	A1 * a2 =new A1;
	A1 * a3 =new A1;
	A1 * a4 =new A1;
	std::vector<void*> vMemLeaks=Core::Memory::MemoryPoolManager::GetInstance().GetMemoryLeaks();
	if(vMemLeaks.size()!=4)
		return Core::errFailed;

	for(uint32 i=0; i<vMemLeaks.size(); ++i)
	{
		if(vMemLeaks[i]!=a1 && vMemLeaks[i]!=a2 && vMemLeaks[i]!=a3 && vMemLeaks[i]!=a4)
			return Core::errFailed;
	}

	delete a1;
	delete a2;
	delete a3;
	delete a4;

	return Core::errOK;
}
